<%@ page language="java" contentType="text/javascript; charset=UTF-8"
  pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.DecimalFormat"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@page import='java.sql.*' %>
<%@page import="java.util.ArrayList"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONSerializer"%>
<%@page import="net.sf.json.JSONArray"%>

<%String callback = request.getParameter("callback");%>
<%=callback %> (<%
	
	String kind = request.getParameter("kind");
	String num = request.getParameter("num");
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	JSONObject jo = new JSONObject();
	
	try{
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection("jdbc:mysql://localhost/itscreater", "itscreater", "campus123");
		
		if(kind.equals("tingclick") || kind.equals("maptingclick")){     
			String update = "update Ting set Count = Count+1 where Number = ?;";
			pstmt = conn.prepareStatement(update);
			pstmt.setString(1, num);
			pstmt.executeUpdate();
			
			jo.put("success", "true");
			out.print(jo);
		} else if(kind.equals("listclick")){
			String update = "update UIcount set List = List+1;";
			pstmt = conn.prepareStatement(update);
			pstmt.executeUpdate();
			
			jo.put("success", "true");
			out.print(jo);
		} else if(kind.equals("mapclick")){
			String update = "update UIcount set Map = Map+1;";
			pstmt = conn.prepareStatement(update);
			pstmt.executeUpdate();
			
			jo.put("success", "true");
			out.print(jo);
		} else{
		}
	}
	finally{
		try{
			pstmt.close();
		}
		catch (Exception ignored){
		}
		try{
			conn.close();
		}
		catch (Exception ignored){
		}
	}
%>);
